package android.slc.appbase.api.slc.callback;

import android.slc.appbase.api.slc.callback.po.SlcEntity;
import android.slc.or.SlcCallbackConfig;

import org.jetbrains.annotations.NotNull;

import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;

public abstract class SlcObserver<T> implements Observer<SlcEntity<T>>, SlcObserverProxy<SlcEntity<T>>, SlcObserverProxy.SlcObserverProxyCallback<T> {

    protected final SlcObserverProxy<T> slcObserverProxy;

    public SlcObserver() {
        this(SlcCallbackConfig.defSlcCallbackConfig);
    }

    public SlcObserver(SlcCallbackConfig slcCallbackConfig) {
        slcObserverProxy = new SlcObserverProxyImpl<T>(slcCallbackConfig,this);
    }

    @Override
    public void onSubscribe(@NotNull Disposable d) {
        onStart();
    }

    @Override
    public void onStart() {
        slcObserverProxy.onStart();
    }

    @Override
    public void onNext(@NonNull SlcEntity<T> tSlcEntity) {
        slcObserverProxy.onNext(tSlcEntity.getData());
    }

    @Override
    public void onError(@NonNull Throwable e) {
        slcObserverProxy.onError(e);
    }

    @Override
    public void onComplete() {
        slcObserverProxy.onComplete();
    }

}
